package com.wanbangee.marksystem.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wanbangee.marksystem.entities.USubject;
import com.wanbangee.marksystem.service.USubjectService;

@RestController
@RequestMapping("subjectManage")
public class USubjectController {
	
	@Autowired
	private USubjectService uSubjectService;
	
	@GetMapping("selectAllSubject")
	public Map<String, Object> selectAllSubject(Integer paging,Integer size,Integer schId){
		Map<String, Object> map = new HashMap<>();
		List<USubject> lists = uSubjectService.selectAllSubjectBypaging(paging, size,schId);
		Integer total=uSubjectService.selectAllSubject(schId).size();
		map.put("code", "1001");
		map.put("message", "接口成功");
		map.put("total",total);
		map.put("lists", lists);
		return map;
	}
	
	@GetMapping("selectSubjectByLikesubNm")
	public Map<String, Object> selectSubjectByLikesubNm(Integer schId,String subNm){
		Map<String, Object> map = new HashMap<>();
		List<USubject> lists = uSubjectService.selectSubjectByLikesubNm(schId, subNm);
		map.put("code", "1001");
		map.put("message", "接口成功");
		map.put("lists", lists);
		return map;
	}
	
	@PostMapping("insertSubject")
	public Map<String, Object> insertSubject(USubject uSubject) {
		Map<String, Object> map = new HashMap<>();
		int insertState = this.uSubjectService.insertSubject(uSubject);
		if(insertState > 0) {
			map.put("code", "1001");
			map.put("message", "接口成功");
		}
		return map;
	}
	
	@GetMapping("selectSubjectBysubId")
	public Map<String, Object> selectSubjectBysubId(int subId,Integer schId) {
		Map<String, Object> map = new HashMap<>();
		USubject uSubject = this.uSubjectService.selectSubjectBysubId(subId,schId);
		map.put("code", "1001");
		map.put("message", "接口成功");
		map.put("uSubject", uSubject);
		return map;
	}
	
	@PutMapping("updateSubject")
	public Map<String, Object> updateSubject(USubject uSubject) {
		Map<String, Object> map = new HashMap<>();
		int updateSubjectState = this.uSubjectService.updateSubject(uSubject);
		if(updateSubjectState > 0) {
			map.put("code", "1001");
			map.put("message", "接口成功");
		}
		return map;
	}
	
	@PutMapping("updateSubjectState")
	public Map<String, Object> updateSubjectState(int subId, int subState) {
		Map<String, Object> map = new HashMap<>();
		int updateSubjectStateState = this.uSubjectService.updateSubjectStat(subId, subState);
		if(updateSubjectStateState > 0) {
			map.put("code", "1001");
			map.put("message", "接口成功");
		}
		return map;
	}
	@PutMapping("deleteSubject")
	public Map<String, Object> deleteSubject(int subId,Integer schId) {
		Map<String, Object> map = new HashMap<>();
		int deleteSubjectState = this.uSubjectService.deleteSubject(subId,schId);
		if(deleteSubjectState > 0) {
			map.put("code", "1001");
			map.put("message", "接口成功");
		}
		return map;
	}
}
